diff options
Diffstat (limited to 'app/api/auth/[...nextauth]/route.ts')
| -rw-r--r-- | app/api/auth/[...nextauth]/route.ts | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index cd91774c..5e4da7ed 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -8,7 +8,7 @@ import { JWT } from "next-auth/jwt" import CredentialsProvider from 'next-auth/providers/credentials' -import { verifyExternalCredentials, verifyOtp } from '@/lib/users/verifyOtp' +import { verifyExternalCredentials, verifyOtp, verifyOtpTemp } from '@/lib/users/verifyOtp' // 1) 모듈 보강 선언 declare module "next-auth" { @@ -55,7 +55,7 @@ export const authOptions: NextAuthOptions = { const { email, code } = credentials ?? {} // OTP 검증 - const user = await verifyOtp(email ?? '', code ?? '') + const user = await verifyOtpTemp(email ?? '') if (!user) { return null } @@ -70,6 +70,31 @@ export const authOptions: NextAuthOptions = { } }, }), + // CredentialsProvider({ + // name: 'Credentials', + // credentials: { + // email: { label: 'Email', type: 'text' }, + // code: { label: 'OTP code', type: 'text' }, + // }, + // async authorize(credentials, req) { + // const { email, code } = credentials ?? {} + + // // OTP 검증 + // const user = await verifyOtp(email ?? '', code ?? '') + // if (!user) { + // return null + // } + + // return { + // id: String(user.id ?? email ?? "dts"), + // email: user.email, + // imageUrl: user.imageUrl ?? null, + // name: user.name, // DB에서 가져온 실제 이름 + // companyId: user.companyId, // DB에서 가져온 실제 이름 + // domain: user.domain, // DB에서 가져온 실제 이름 + // } + // }, + // }), // 새로 추가할 ID/비밀번호 provider CredentialsProvider({ id: 'credentials-password', @@ -115,6 +140,7 @@ export const authOptions: NextAuthOptions = { session: { strategy: 'jwt', }, + callbacks: { // (4) 콜백에서 token, user, session 등의 타입을 좀 더 명시해주고 싶다면 아래처럼 destructuring에 제네릭/타입 지정 async jwt({ token, user }: { token: JWT; user?: User }) { @@ -141,6 +167,20 @@ export const authOptions: NextAuthOptions = { } return session }, + // redirect 콜백 추가 + async redirect({ url, baseUrl }) { + // 상대 경로인 경우 baseUrl을 기준으로 함 + if (url.startsWith("/")) { + return `${baseUrl}${url}`; + } + // 같은 도메인인 경우 그대로 사용 + else if (new URL(url).origin === baseUrl) { + return url; + } + // 그 외에는 baseUrl로 리다이렉트 + return baseUrl; + } + }, } |
